home *** CD-ROM | disk | FTP | other *** search
/ Software Vault: The Gold Collection / Software Vault - The Gold Collection (American Databankers) (1993).ISO / cdr49 / pgp23src.zip / ZUNZIP.H < prev   
C/C++ Source or Header  |  1993-05-09  |  11KB  |  316 lines

  1. /*---------------------------------------------------------------------------
  2.  
  3.   unzip.h
  4.  
  5.   This header file is used by all of the unzip source files.  Its contents
  6.   were divided into seven more-or-less separate sections but have been
  7.   hacked to death to minimize the total size and maximize compile speed by
  8.   not including stuff not needed for the inflate-only compile.
  9.  
  10.   Modified 25 Jun 92 - HAJK
  11.   Fix support for use in PGP/VMS
  12.   ---------------------------------------------------------------------------*/
  13.  
  14. /***************************/
  15. /*  OS-Dependent Includes  */
  16. /***************************/
  17.  
  18. #include    <stdlib.h>
  19. #include    "usuals.h"
  20. #include    "system.h"
  21.  
  22. #ifndef MINIX            /* Minix needs it after all the other includes (?) */
  23. #  include <stdio.h>     /* this is your standard header for all C compiles */
  24. #endif
  25.  
  26. /*---------------------------------------------------------------------------
  27.     Next, a word from our Unix (mostly) sponsors:
  28.   ---------------------------------------------------------------------------*/
  29.  
  30. #ifdef UNIX
  31. #  ifdef AMIGA
  32. #    include <libraries/dos.h>
  33. #  else /* !AMIGA */
  34. #    ifndef NO_PARAM_H
  35. #      include <sys/param.h>   /* conflict with <sys/types.h>, some systems? */
  36. #    endif /* !NO_PARAM_H */
  37. #  endif /* ?AMIGA */
  38.  
  39. #  ifndef BSIZE
  40. #    ifdef MINIX
  41. #      define BSIZE   1024
  42. #    else /* !MINIX */
  43. #      define BSIZE   DEV_BSIZE  /* assume common for all Unix systems */
  44. #    endif /* ?MINIX */
  45. #  endif
  46.  
  47. #  ifndef BSD
  48. #    if !defined(AMIGA) && !defined(MINIX)
  49. #      define NO_MKDIR           /* for mapped_name() */
  50. #    endif /* !AMIGA && !MINIX */
  51. #    include <time.h>
  52. #  else   /* BSD */
  53. #    include <sys/time.h>
  54. #    include <sys/timeb.h>
  55. #  endif
  56.  
  57. #else   /* !UNIX */
  58. #  define BSIZE   512               /* disk block size */
  59. #endif /* ?UNIX */
  60.  
  61. /*---------------------------------------------------------------------------
  62.     And now, our MS-DOS and OS/2 corner:
  63.   ---------------------------------------------------------------------------*/
  64.  
  65. #ifdef __TURBOC__
  66. #  define DOS_OS2             /* Turbo C under DOS, MSC under DOS or OS2    */
  67. #  ifndef __BORLANDC__        /* There appears to be a bug ?? in Borland's  */
  68. #    include <alloc.h>
  69. #  endif
  70. #else                         /* NOT Turbo C...                             */
  71. #  ifdef MSDOS                /*   but still MS-DOS, so we'll assume it's   */
  72. #    ifndef MSC               /*   Microsoft's compiler and fake the ID, if */
  73. #      define MSC             /*   necessary (it is in 5.0; apparently not  */
  74. #    endif                    /*   in 5.1 and 6.0)                          */
  75. #    include <dos.h>          /* _dos_setftime()                            */
  76. #  endif
  77. #  ifdef OS2                  /* stuff for DOS and OS/2 family version */
  78. #    ifndef MSC
  79. #      define MSC
  80. #    endif
  81. #    define INCL_BASE
  82. #    define INCL_NOPM
  83. #    include <os2.h>          /* DosQFileInfo(), DosSetFileInfo()? */
  84. #  endif
  85. #endif
  86.  
  87. #ifdef MSC                    /* defined for all versions of MSC now         */
  88. #  define DOS_OS2             /* Turbo C under DOS, MSC under DOS or OS/2    */
  89. #  if defined(_MSC_VER) && (_MSC_VER >= 600)      /* new with 5.1 or 6.0 ... */
  90. #    undef DECLARE_ERRNO      /* errno is now a function in a dynamic link   */
  91. #  endif                      /*   library (or something)--incompatible with */
  92. #endif                        /*   the usual "extern int errno" declaration  */
  93.  
  94. #ifdef DOS_OS2                /* defined for both Turbo C, MSC */
  95. #  include <io.h>             /* lseek(), open(), setftime(), dup(), creat() */
  96. #  include <time.h>           /* localtime() */
  97. #endif
  98.  
  99. /*---------------------------------------------------------------------------
  100.     Followed by some VMS (mostly) stuff:
  101.   ---------------------------------------------------------------------------*/
  102.  
  103. #ifdef VMS
  104. #  include <time.h>             /* the usual non-BSD time functions */
  105. #  include <file.h>             /* same things as fcntl.h has */
  106. #  include <rmsdef.h>           /* RMS error codes */
  107. #  define UNIX            /* can share most of same code from now on */
  108. #  define RETURN   return    /* Don't Fake return    */
  109. #else /* !VMS */
  110. #  define RETURN   return       /* only used in main() */
  111. #  ifdef V7
  112. #    define O_RDONLY  0
  113. #    define O_WRONLY  1
  114. #    define O_RDWR    2
  115. #  else /* !V7 */
  116. #    ifdef MTS
  117. #      include <sys/file.h>     /* MTS uses this instead of fcntl.h */
  118. #    else /* !MTS */
  119. #      ifdef COHERENT           /* Coherent 3.10/Mark Williams C */
  120. #        include <sys/fcntl.h>
  121. #        define SHORT_NAMES
  122. #        define tzset  settz
  123. #      else /* !COHERENT */
  124. #        include <fcntl.h>      /* #define O_BINARY 0x8000 (no CR/LF */
  125. #      endif /* ?COHERENT */    /*   translation), as used in open() */
  126. #    endif /* ?MTS */
  127. #  endif /* ?V7 */
  128. #endif /* ?VMS */
  129.  
  130. /*---------------------------------------------------------------------------
  131.     And some Mac stuff for good measure:
  132.   ---------------------------------------------------------------------------*/
  133.  
  134. #ifdef THINK_C
  135. #  define MACOS
  136. #  ifndef __STDC__            /* THINK_C isn't truly ANSI-standard, */
  137. #    define __STDC__ 1        /*   but it understands prototypes...so */
  138. #  endif                      /*   it's close enough for our purposes */
  139. #  include <time.h>
  140. #  include <unix.h>
  141. #  include "macstat.h"
  142. #endif
  143. #ifdef MPW                    /* not tested yet - should be easy enough tho */
  144. #  define MACOS
  145. #  include <time.h>
  146. #  include <fcntl.h>
  147. #  include "macstat.h"
  148. #endif
  149.  
  150. /*---------------------------------------------------------------------------
  151.     And finally, some random extra stuff:
  152.   ---------------------------------------------------------------------------*/
  153.  
  154. #include <stdlib.h>      /* standard library prototypes, malloc(), etc. */
  155. #include <string.h>      /* defines strcpy, strcmp, memcpy, etc. */
  156.  
  157. #ifdef MINIX
  158. #  include <stdio.h>
  159. #endif
  160.  
  161.  
  162. /*************/
  163. /*  Defines  */
  164. /*************/
  165.  
  166. #define INBUFSIZ          BUFSIZ   /* same as stdio uses */
  167. #define OUTBUFSIZ       0x2000     /* unImplode needs power of 2, >= 0x2000 */
  168.  
  169. #define MAX_BITS      13                 /* used in unShrink() */
  170. #define HSIZE         (1 << MAX_BITS)    /* size of global work area */
  171.  
  172. #define LF   10   /* '\n' on ASCII machines.  Must be 10 due to EBCDIC */
  173. #define CR   13   /* '\r' on ASCII machines.  Must be 13 due to EBCDIC */
  174.  
  175. #ifdef AMIGA
  176. #  define FFLUSH    fflush(stderr);
  177. #else /* !AMIGA */
  178. #  define FFLUSH
  179. #endif /* ?AMIGA */
  180.  
  181. #ifndef TRUE
  182. #  define TRUE      1   /* sort of obvious */
  183. #  define FALSE     0
  184. #endif
  185.  
  186. #ifndef SEEK_SET        /* These should all be declared in stdio.h!  But   */
  187. #  define SEEK_SET  0   /*  since they're not (in many cases), do so here. */
  188. #  define SEEK_CUR  1
  189. #  define SEEK_END  2
  190. #endif
  191.  
  192. /**************/
  193. /*  Typedefs  */
  194. /**************/
  195.  
  196. typedef long             longint;
  197. typedef unsigned short   UWORD;
  198. #ifndef OS2
  199. typedef unsigned long    ULONG;
  200. #endif
  201.  
  202. /*************************/
  203. /*  Function Prototypes  */
  204. /*************************/
  205.  
  206. #ifdef PROTO
  207.  
  208. /* The following is for non-ansi compilers supporting prototypes */
  209. /* (e.g. old SGI compilers and Borland C in non-ansi mode */ 
  210.  
  211. #define __(X)   X   /*  Inc.  Should probably give them a call and see   */
  212. #endif
  213.  
  214. #ifndef __              /* This amusing little construct was swiped without  */
  215. #  if __STDC__          /*  permission from the fine folks at Cray Research, */
  216. #    define __(X)   X   /*  Inc.  Should probably give them a call and see   */
  217. #  else                 /*  if they mind, but....  Then again, I can't think */
  218. #    define __(X)   ()  /*  of any other way to do this, so maybe it's an    */
  219. #  endif                /*  algorithm?  Whatever, thanks to CRI.  (Note:     */
  220. #endif                  /*  keep interior stuff parenthesized.)              */
  221. /*
  222.  * Toad Hall Note:  Not to worry:  I've seen this somewhere else too,
  223.  * so obviously it's been stolen more than once.
  224.  * That makes it public domain, right?
  225.  */
  226.  
  227. /*---------------------------------------------------------------------------
  228.     Functions in file_io.c and crypt.c:
  229.   ---------------------------------------------------------------------------*/
  230.  
  231. int    open_input_file           __( (void) );
  232. int    readbuf                   __( (char *buf, register unsigned size) );
  233. int    create_output_file        __( (void) );
  234. int    FillBitBuffer             __( (void) );
  235. int    ReadByte                  __( (UWORD *x) );
  236. int    FlushOutput               __( (void) );
  237.  
  238. /*---------------------------------------------------------------------------
  239.     Uncompression functions (all internal compression routines, enclosed in
  240.     comments below, are prototyped in their respective files and are invisi-
  241.     ble to external functions):
  242.   ---------------------------------------------------------------------------*/
  243.  
  244. void   inflate                  __( (void) );                  /* inflate.c */
  245. int unzip                __( ( FILE *inFile, FILE *outFile ) );
  246.  
  247. /************/
  248. /*  Macros  */
  249. /************/
  250.  
  251. #ifndef min    /* MSC defines this in stdlib.h */
  252. #  define min(a,b)   ((a) < (b) ? (a) : (b))
  253. #endif
  254.  
  255. #define OUTB(intc) {*outptr++=intc; if (++outcnt==OUTBUFSIZ) FlushOutput();}
  256.  
  257. /*
  258.  *  macro OUTB(intc)
  259.  *  {
  260.  *      *outptr++ = intc;
  261.  *      if (++outcnt == OUTBUFSIZ)
  262.  *          FlushOutput();
  263.  *  }
  264.  *
  265.  */
  266.  
  267.  
  268. #define READBIT(nbits,zdest) \
  269.     do \
  270.     { \
  271.         if(nbits>bits_left) \
  272.             FillBitBuffer(); \
  273.           zdest=(int)(bitbuf&mask_bits[nbits]); \
  274.         bitbuf>>=nbits; \
  275.         bits_left-=nbits; \
  276.     } while(0)
  277.  
  278. /*
  279.  * macro READBIT(nbits,zdest)
  280.  *  {
  281.  *      if (nbits > bits_left)
  282.  *          FillBitBuffer();
  283.  *      zdest = (int)(bitbuf & mask_bits[nbits]);
  284.  *      bitbuf >>= nbits;
  285.  *      bits_left -= nbits;
  286.  *  }
  287.  *
  288.  */
  289.  
  290. #define PEEKBIT(nbits) ( nbits > bits_left ? (FillBitBuffer(), bitbuf & mask_bits[nbits]) : bitbuf & mask_bits[nbits] )
  291.  
  292. /*************/
  293. /*  Globals  */
  294. /*************/
  295.  
  296.    extern longint   csize;
  297.  
  298.    extern ULONG     mask_bits[];
  299.  
  300.    extern byte      *inbuf;
  301.    extern byte      *inptr;
  302.    extern int       incnt;
  303.    extern ULONG     bitbuf;
  304.    extern int       bits_left;
  305.    extern boolean   zipeof;
  306.    extern int       zipfd;
  307.    extern char      zipfn[];
  308.  
  309.    extern byte      *outbuf;
  310.    extern byte      *outptr;
  311.    extern byte      *outout;
  312.    extern longint   outpos;
  313.    extern int       outcnt;
  314.    extern int       outfd;
  315.    extern int       disk_full;
  316.